************
* title: Replication: Traditional Leaders and the 2014-2015 Ebola Epidemic
* author: Peter van der Windt & Maarten Voors
* Journal: Journal of Politics
* date: "June, 2019"
************

* This do-file prepares the datasets
* Analysis is done in "Replication.Rmd"

* Set your directory
	* ...
	* In this directory make sure to have the following folders:
	** 01_data (place the raw datasets in this folder)
	** 02_temp
	** 03_output

********
** Core
********

	* Core.dta
	* Contains 149 hand-coded Chiefdom names
	* This is the file to which we will merge everything to

********
** Acemoglu et al (2014)
********

	use 01_data/chiefs_survey_clean_out.dta, clear
	ren chiefcode CHIEFDOM
	save 02_temp/chiefs_survey_clean_out.dta, replace

********
** Fang et al (2016): Ebola confirmed cases
********

	import excel using 01_data/pnas.1518587113.sd02.xlsx, clear firstrow sheet("lab-confirmed database")
	g dummy=1
	g dm=mofd(Dateofsymptomonset)
	format dm %tm
	tostring dm, replace
	destring dm, replace
	g month = dm-651
	g dummySUB1=1 if month>1
	g dummySUB2=1 if month>2
	g dummySUB3=1 if month>3
	g dummySUB4=1 if month>4
	g dummySUB5=1 if month>5
	g dummySUB6=1 if month>6
	g dummySUB7=1 if month>7
	g dummySUB8=1 if month>8
	g dummySUB9=1 if month>9
	g dummySUB10=1 if month>10
	g dummySUB11=1 if month>11
	g dummySUB12=1 if month>12
	by District Chiefdom, sort: egen ebola_confirmed=total(dummy)
	by District Chiefdom, sort: egen ebola_confirmedSUB1=total(dummySUB1)
	by District Chiefdom, sort: egen ebola_confirmedSUB2=total(dummySUB2)
	by District Chiefdom, sort: egen ebola_confirmedSUB3=total(dummySUB3)
	by District Chiefdom, sort: egen ebola_confirmedSUB4=total(dummySUB4)
	by District Chiefdom, sort: egen ebola_confirmedSUB5=total(dummySUB5)
	by District Chiefdom, sort: egen ebola_confirmedSUB6=total(dummySUB6)
	by District Chiefdom, sort: egen ebola_confirmedSUB7=total(dummySUB7)
	by District Chiefdom, sort: egen ebola_confirmedSUB8=total(dummySUB8)
	by District Chiefdom, sort: egen ebola_confirmedSUB9=total(dummySUB9)
	by District Chiefdom, sort: egen ebola_confirmedSUB10=total(dummySUB10)
	by District Chiefdom, sort: egen ebola_confirmedSUB11=total(dummySUB11)
	by District Chiefdom, sort: egen ebola_confirmedSUB12=total(dummySUB12)
	* Time between onset and test
	tostring Dateofsymptomonset,replace
	destring Dateofsymptomonset,replace
	tostring Dateofsampletested,replace
	destring Dateofsampletested,replace
	g X=Dateofsampletested-Dateofsymptomonset
	by District Chiefdom, sort: egen conf_TimeOnsetTest=mean(X)
	collapse ebola_confirmed ebola_confirmedSUB* conf_TimeOnsetTest, by(District Chiefdom)
	* rename the chiefdoms for good merge with Core. 
	* Many of them do not change because Core and Ebola are the same
	********************************************
	replace Chiefdom= "Badjia" if District== "Bo" & Chiefdom== "Badjia"
	replace Chiefdom= "Bagbo" if District== "Bo" & Chiefdom== "Bagbo"
	replace Chiefdom= "Baoma" if District== "Bo" & Chiefdom== "Baoma"
	replace Chiefdom= "Bumpe Ngao" if District== "Bo" & Chiefdom== "Bumpe Ngawo"
	replace Chiefdom= "Gbo" if District== "Bo" & Chiefdom== "Gbo"
	replace Chiefdom= "Jaiama Bongor" if District== "Bo" & Chiefdom== "Jaiama Bongor"
	replace Chiefdom= "Kakua" if District== "Bo" & Chiefdom== "Kakua"
	replace Chiefdom= "Komboya" if District== "Bo" & Chiefdom== "Komboya"
	replace Chiefdom= "Lugbu" if District== "Bo" & Chiefdom== "Lugbu"
	replace Chiefdom= "Niawa Lenga" if District== "Bo" & Chiefdom== "Niawa Lenga"
	replace Chiefdom= "Selenga" if District== "Bo" & Chiefdom== "Selenga"
	replace Chiefdom= "Tikonko" if District== "Bo" & Chiefdom== "Tikonko"
	replace Chiefdom= "Valunia" if District== "Bo" & Chiefdom== "Valunia"
	replace Chiefdom= "Wonde" if District== "Bo" & Chiefdom== "Wunde"
	replace Chiefdom= "Biriwa" if District== "Bombali" & Chiefdom== "Biriwa"
	replace Chiefdom= "Bombali Sebora" if District== "Bombali" & Chiefdom== "Bombali Sebora"
	replace Chiefdom= "Gbanti Kamaranka" if District== "Bombali" & Chiefdom== "Gbanti-Kamaranka"
	replace Chiefdom= "Gbendembu Ngowahun" if District== "Bombali" & Chiefdom== "Ngowahun"
	replace Chiefdom= "Libeisaygahun" if District== "Bombali" & Chiefdom== "Libeisaygahun"
	replace Chiefdom= "Makari Gbanti" if District== "Bombali" & Chiefdom== "Makari Gbanti"
	replace Chiefdom= "Paki Masabong" if District== "Bombali" & Chiefdom== "Paki Masabong"
	replace Chiefdom= "Safroko Limba" if District== "Bombali" & Chiefdom== "Safroko Limba"
	replace Chiefdom= "Sanda Loko" if District== "Bombali" & Chiefdom== "Sanda Loko"
	replace Chiefdom= "Sanda Tendaran" if District== "Bombali" & Chiefdom== "Sanda Tendaren"
	replace Chiefdom= "Sella Limba" if District== "Bombali" & Chiefdom== "Sella Limba"
	replace Chiefdom= "Tambakha" if District== "Bombali" & Chiefdom== "Tambakka"
	replace Chiefdom= "Imperri" if District== "Bonthe" & Chiefdom== "Imperi"
	replace Chiefdom= "Jong" if District== "Bonthe" & Chiefdom== "Jong"
    replace Chiefdom= "Sogbeni" if District== "Bonthe" & Chiefdom== "Sogbini"
    replace Chiefdom= "Dea" if District== "Kailahun" & Chiefdom== "Dea"
	replace Chiefdom= "Jawie" if District== "Kailahun" & Chiefdom== "Jawei"
	replace Chiefdom= "Kissi Kama" if District== "Kailahun" & Chiefdom== "Kissi Kama"
	replace Chiefdom= "Kissi Teng" if District== "Kailahun" & Chiefdom== "Kissi Teng"
	replace Chiefdom= "Kissi Tongi" if District== "Kailahun" & Chiefdom== "Kissi Tonge"
	replace Chiefdom= "Kpeje Bongre" if District== "Kailahun" & Chiefdom== "Peje Bongre"
	replace Chiefdom= "Kpeje West" if District== "Kailahun" & Chiefdom== "Peje West"
	replace Chiefdom= "Luawa" if District== "Kailahun" & Chiefdom== "Luawa"
	replace Chiefdom= "Malema" if District== "Kailahun" & Chiefdom== "Malema"
	replace Chiefdom= "Mandu" if District== "Kailahun" & Chiefdom== "Mandu"
	replace Chiefdom= "Njaluahun" if District== "Kailahun" & Chiefdom== "Njaluahun"
	replace Chiefdom= "Penguia" if District== "Kailahun" & Chiefdom== "Penguia"
	replace Chiefdom= "Upper Bambara" if District== "Kailahun" & Chiefdom== "Upper Bambara"
	replace Chiefdom= "Yawei" if District== "Kailahun" & Chiefdom== "Yawei"
	replace Chiefdom= "Bramaia" if District== "Kambia" & Chiefdom== "Bramaia"
	replace Chiefdom= "Gbinle Dixin" if District== "Kambia" & Chiefdom== "Gbinle-Dixing"
	replace Chiefdom= "Mabolo" if District== "Kambia" & Chiefdom== "Mambolo"
	replace Chiefdom= "Magbema" if District== "Kambia" & Chiefdom== "Magbema"
	replace Chiefdom= "Masungbala" if District== "Kambia" & Chiefdom== "Masungbala"
	replace Chiefdom= "Samu" if District== "Kambia" & Chiefdom== "Samu"
	replace Chiefdom= "Tonko Limba" if District== "Kambia" & Chiefdom== "Tonko Limba"
	replace Chiefdom= "Dodo" if District== "Kenema" & Chiefdom== "Dodo"
	replace Chiefdom= "Gaura" if District== "Kenema" & Chiefdom== "Gaura"
	replace Chiefdom= "Gorama Mende" if District== "Kenema" & Chiefdom== "Gorama Mende"
	replace Chiefdom= "Kandu Leppiama" if District== "Kenema" & Chiefdom== "Kandu Leppiama"
	replace Chiefdom= "Koya" if District== "Kenema" & Chiefdom== "Koya"
	replace Chiefdom= "Lower Bambara" if District== "Kenema" & Chiefdom== "Lower Bambara"
	replace Chiefdom= "Malegohun" if District== "Kenema" & Chiefdom== "Niawa"
	replace Chiefdom= "Nongowa" if District== "Kenema" & Chiefdom== "Nongowa"
	replace Chiefdom= "Simbaru" if District== "Kenema" & Chiefdom== "Simbaru"
	replace Chiefdom= "Small Bo" if District== "Kenema" & Chiefdom== "Small Bo"
	replace Chiefdom= "Tunkia" if District== "Kenema" & Chiefdom== "Tunkia"
	replace Chiefdom= "Wandor" if District== "Kenema" & Chiefdom== "Wandor"
	replace Chiefdom= "Kasunko" if District== "Koinadugu" & Chiefdom== "Kasonko"
	replace Chiefdom= "Nieni" if District== "Koinadugu" & Chiefdom== "Neini"
	replace Chiefdom= "Wara Wara Yagala" if District== "Koinadugu" & Chiefdom== "Wara Wara Yagala"
	replace Chiefdom= "Gbane" if District== "Kono" & Chiefdom== "Gbane"
	replace Chiefdom= "Gbane Kandor" if District== "Kono" & Chiefdom== "Gbane Kandor"
	replace Chiefdom= "Gbense" if District== "Kono" & Chiefdom== "Gbense"
	replace Chiefdom= "Gorama Kono" if District== "Kono" & Chiefdom== "Gorama Kono"
	replace Chiefdom= "Kamara" if District== "Kono" & Chiefdom== "Kamara"
	replace Chiefdom= "Lei" if District== "Kono" & Chiefdom== "Lei"
	replace Chiefdom= "Nimikoro" if District== "Kono" & Chiefdom== "Nimikoro"
	replace Chiefdom= "Nimiyama" if District== "Kono" & Chiefdom== "Nimiyama"
	replace Chiefdom= "Sandor" if District== "Kono" & Chiefdom== "Sandor"
	replace Chiefdom= "Soa" if District== "Kono" & Chiefdom== "Soa"
	replace Chiefdom= "Tankoro" if District== "Kono" & Chiefdom== "Tankoro"
	replace Chiefdom= "Bahruwa" if District== "Moyamba" & Chiefdom== "Bagruwa"
	replace Chiefdom= "Bumpeh" if District== "Moyamba" & Chiefdom== "Bumpeh"
	replace Chiefdom= "Fakunya" if District== "Moyamba" & Chiefdom== "Fakunya"
	replace Chiefdom= "Kagboro" if District== "Moyamba" & Chiefdom== "Kargboro"
	replace Chiefdom= "Kaiyamba" if District== "Moyamba" & Chiefdom== "Kaiyamba"
	replace Chiefdom= "Kori" if District== "Moyamba" & Chiefdom== "Kori"
	replace Chiefdom= "Kowa" if District== "Moyamba" & Chiefdom== "Kowa"
	replace Chiefdom= "Lower Banta (Gbanbatoke)" if District== "Moyamba" & Chiefdom== "Banta Gbangbatote"
	replace Chiefdom= "Ribbi" if District== "Moyamba" & Chiefdom== "Ribbi"
	replace Chiefdom= "Timbale" if District== "Moyamba" & Chiefdom== "Timidale"
	replace Chiefdom= "Bureh Kasseh Makonteh (BKM)" if District== "Port Loko" & Chiefdom== "Bkm"
	replace Chiefdom= "Buya" if District== "Port Loko" & Chiefdom== "Buya Romende"
	replace Chiefdom= "Dibia" if District== "Port Loko" & Chiefdom== "Dibia"
	replace Chiefdom= "Kaffu Bullom" if District== "Port Loko" & Chiefdom== "Kaffu Bullom"
	replace Chiefdom= "Koya" if District== "Port Loko" & Chiefdom== "Koya"
	replace Chiefdom= "Lokomasama" if District== "Port Loko" & Chiefdom== "Lokomasam"
	replace Chiefdom= "Maforki" if District== "Port Loko" & Chiefdom== "Maforki"
	replace Chiefdom= "Marampa" if District== "Port Loko" & Chiefdom== "Marampa"
	replace Chiefdom= "Masimera" if District== "Port Loko" & Chiefdom== "Masimera"
	replace Chiefdom= "Sanda Magbolontor" if District== "Port Loko" & Chiefdom== "Sanda Magbolontor"
	replace Chiefdom= "Tinkatupa Maka Saffroko (TMS)" if District== "Port Loko" & Chiefdom== "Tms"
	replace Chiefdom= "Barri" if District== "Pujehun" & Chiefdom== "Barri"
	replace Chiefdom= "Kpaka" if District== "Pujehun" & Chiefdom== "Kpaka"
	replace Chiefdom= "Makpele" if District== "Pujehun" & Chiefdom== "Makpele"
	replace Chiefdom= "Malen" if District== "Pujehun" & Chiefdom== "Malen"
	replace Chiefdom= "Panga Kabonde" if District== "Pujehun" & Chiefdom== "Kpanga Kabonde"
	replace Chiefdom= "Panga Krim" if District== "Pujehun" & Chiefdom== "Panga Krim"
	replace Chiefdom= "Gbonkolenken" if District== "Tonkolili" & Chiefdom== "Gbonkolenken"
	replace Chiefdom= "Kafe Simiria" if District== "Tonkolili" & Chiefdom== "Kafe Simiria"
    replace Chiefdom= "Kholifa Mabang" if District== "Tonkolili" & Chiefdom== "Kholifa Mabang"
	replace Chiefdom= "Kholifa Rowala" if District== "Tonkolili" & Chiefdom== "Kholifa"
	replace Chiefdom= "Kunike" if District== "Tonkolili" & Chiefdom== "Konike Sanda"
	replace Chiefdom= "Kunike Barina" if District== "Tonkolili" & Chiefdom== "Konike Barina"
	replace Chiefdom= "Malal Mara" if District== "Tonkolili" & Chiefdom== "Malal Mara"
	replace Chiefdom= "Tane" if District== "Tonkolili" & Chiefdom== "Tane"
	replace Chiefdom= "Yoni" if District== "Tonkolili" & Chiefdom== "Yoni" 
	********************************************
	replace District=trim(upper(District))
	replace Chiefdom=trim(upper(Chiefdom))
	sort District Chiefdom
	save 02_temp/pnas.1518587113.sd02_confirmed.dta, replace
	
********
** Fang et al (2016): Ebola suspected cases
********
	
	import excel using 01_data/pnas.1518587113.sd02.xlsx, clear firstrow sheet("suspected database")
	g dummy=1
	by District Chiefdom, sort: egen ebola_suspected=total(dummy)
	* Time between onset and test
	tostring Dateofsymptomonset,replace
	destring Dateofsymptomonset,replace
	tostring Dateofsampletested,replace
	destring Dateofsampletested,replace
	g X=Dateofsampletested-Dateofsymptomonset
	by District Chiefdom, sort: egen sus_TimeOnsetTest=mean(X)
	collapse ebola_suspected sus_TimeOnsetTest, by(District Chiefdom)
	* rename the chiefdoms for good merge with Core. 
	* Many of them do not change because Core and Ebola are the same
	********************************************
	replace Chiefdom= "Badjia" if District== "Bo" & Chiefdom== "Badjia"
	replace Chiefdom= "Bagbo" if District== "Bo" & Chiefdom== "Bagbo"
	replace Chiefdom= "Bagbwe" if District== "" & Chiefdom== ""
	replace Chiefdom= "Baoma" if District== "Bo" & Chiefdom== "Baoma"
	replace Chiefdom= "Bumpe Ngao" if District== "Bo" & Chiefdom== "Bumpe Ngawo"
	replace Chiefdom= "Gbo" if District== "Bo" & Chiefdom== "Gbo"
	replace Chiefdom= "Jaiama Bongor" if District== "Bo" & Chiefdom== "Jaiama Bongor"
	replace Chiefdom= "Kakua" if District== "Bo" & Chiefdom== "Kakua"
	replace Chiefdom= "Komboya" if District== "Bo" & Chiefdom== "Komboya"
	replace Chiefdom= "Lugbu" if District== "Bo" & Chiefdom== "Lugbu"
	replace Chiefdom= "Niawa Lenga" if District== "Bo" & Chiefdom== "Niawa Lenga"
	replace Chiefdom= "Selenga" if District== "Bo" & Chiefdom== "Selenga"
	replace Chiefdom= "Tikonko" if District== "Bo" & Chiefdom== "Tikonko"
	replace Chiefdom= "Valunia" if District== "Bo" & Chiefdom== "Valunia"
	replace Chiefdom= "Wonde" if District== "Bo" & Chiefdom== "Wunde"
	replace Chiefdom= "Biriwa" if District== "Bombali" & Chiefdom== "Biriwa"
	replace Chiefdom= "Bombali Sebora" if District== "Bombali" & Chiefdom== "Bombali Sebora"
	replace Chiefdom= "Gbanti Kamaranka" if District== "Bombali" & Chiefdom== "Gbanti-Kamaranka"
	replace Chiefdom= "Gbendembu Ngowahun" if District== "Bombali" & Chiefdom== "Ngowahun"
	replace Chiefdom= "Libeisaygahun" if District== "Bombali" & Chiefdom== "Libeisaygahun"
	replace Chiefdom= "Makari Gbanti" if District== "Bombali" & Chiefdom== "Makari Gbanti"
	replace Chiefdom= "Paki Masabong" if District== "Bombali" & Chiefdom== "Paki Masabong"
	replace Chiefdom= "Safroko Limba" if District== "Bombali" & Chiefdom== "Safroko Limba"
	replace Chiefdom= "Sanda Loko" if District== "Bombali" & Chiefdom== "Sanda Loko"
	replace Chiefdom= "Sanda Tendaran" if District== "Bombali" & Chiefdom== "Sanda Tendaren"
	replace Chiefdom= "Sella Limba" if District== "Bombali" & Chiefdom== "Sella Limba"
	replace Chiefdom= "Tambakha" if District== "Bombali" & Chiefdom== "Tambakka"
	replace Chiefdom= "Bendu-Cha" if District== "Bonthe" & Chiefdom== "Bendu Cha"
	replace Chiefdom= "Imperri" if District== "Bonthe" & Chiefdom== "Imperi"
	replace Chiefdom= "Jong" if District== "Bonthe" & Chiefdom== "Jong"
	replace Chiefdom= "Nongoba" if District== "Bonthe" & Chiefdom== "Nongoba Bullom" 
	replace Chiefdom= "Sogbeni" if District== "Bonthe" & Chiefdom== "Sogbini"
	replace Chiefdom= "Yawbeko" if District== "Bonthe" & Chiefdom== "Yawbeco"
	replace Chiefdom= "Dea" if District== "Kailahun" & Chiefdom== "Dea"
	replace Chiefdom= "Jawie" if District== "Kailahun" & Chiefdom== "Jawei"
	replace Chiefdom= "Kissi Kama" if District== "Kailahun" & Chiefdom== "Kissi Kama"
	replace Chiefdom= "Kissi Teng" if District== "Kailahun" & Chiefdom== "Kissi Teng"
	replace Chiefdom= "Kissi Tongi" if District== "Kailahun" & Chiefdom== "Kissi Tonge"
	replace Chiefdom= "Kpeje Bongre" if District== "Kailahun" & Chiefdom== "Peje Bongre"
	replace Chiefdom= "Kpeje West" if District== "Kailahun" & Chiefdom== "Peje West"
	replace Chiefdom= "Luawa" if District== "Kailahun" & Chiefdom== "Luawa"
	replace Chiefdom= "Malema" if District== "Kailahun" & Chiefdom== "Malema"
	replace Chiefdom= "Mandu" if District== "Kailahun" & Chiefdom== "Mandu"
	replace Chiefdom= "Njaluahun" if District== "Kailahun" & Chiefdom== "Njaluahun"
	replace Chiefdom= "Penguia" if District== "Kailahun" & Chiefdom== "Penguia"
	replace Chiefdom= "Upper Bambara" if District== "Kailahun" & Chiefdom== "Upper Bambara"
	replace Chiefdom= "Yawei" if District== "Kailahun" & Chiefdom== "Yawei"
	replace Chiefdom= "Bramaia" if District== "Kambia" & Chiefdom== "Bramaia"
	replace Chiefdom= "Gbinle Dixin" if District== "Kambia" & Chiefdom== "Gbinle-Dixing"
	replace Chiefdom= "Mabolo" if District== "Kambia" & Chiefdom== "Mambolo"
	replace Chiefdom= "Magbema" if District== "Kambia" & Chiefdom== "Magbema"
	replace Chiefdom= "Masungbala" if District== "Kambia" & Chiefdom== "Masungbala"
	replace Chiefdom= "Samu" if District== "Kambia" & Chiefdom== "Samu"
	replace Chiefdom= "Tonko Limba" if District== "Kambia" & Chiefdom== "Tonko Limba"
	replace Chiefdom= "Dodo" if District== "Kenema" & Chiefdom== "Dodo"
	replace Chiefdom= "Gaura" if District== "Kenema" & Chiefdom== "Gaura"
	replace Chiefdom= "Gorama Mende" if District== "Kenema" & Chiefdom== "Gorama Mende"
	replace Chiefdom= "Kandu Leppiama" if District== "Kenema" & Chiefdom== "Kandu Leppiama"
	replace Chiefdom= "Koya" if District== "Kenema" & Chiefdom== "Koya"
	replace Chiefdom= "Lower Bambara" if District== "Kenema" & Chiefdom== "Lower Bambara"
	replace Chiefdom= "Niawa" if District== "Kenema" & Chiefdom== "Niawa"
	replace Chiefdom= "Nongowa" if District== "Kenema" & Chiefdom== "Nongowa"
	replace Chiefdom= "Simbaru" if District== "Kenema" & Chiefdom== "Simbaru"
	replace Chiefdom= "Small Bo" if District== "Kenema" & Chiefdom== "Small Bo"
	replace Chiefdom= "Tunkia" if District== "Kenema" & Chiefdom== "Tunkia"
	replace Chiefdom= "Wandor" if District== "Kenema" & Chiefdom== "Wandor"
	replace Chiefdom= "Folosaba Dembelia" if District== "Koinadugu" & Chiefdom== "Folasaba Dembelia"
	replace Chiefdom= "Kasunko" if District== "Koinadugu" & Chiefdom== "Kasonko" 
	replace Chiefdom= "Nieni" if District== "Koinadugu" & Chiefdom== "Neini"
	replace Chiefdom= "Wara Wara Bafodia" if District== "Koinadugu" & Chiefdom== "Wara Wara Bafodea"
	replace Chiefdom= "Wara Wara Yagala" if District== "Koinadugu" & Chiefdom== "Wara Wara Yagala"
	replace Chiefdom= "Gbane" if District== "Kono" & Chiefdom== "Gbane"
	replace Chiefdom= "Gbane Kandor" if District== "Kono" & Chiefdom== "Gbane Kandor"
	replace Chiefdom= "Gbense" if District== "Kono" & Chiefdom== "Gbense"
	replace Chiefdom= "Gorama Kono" if District== "Kono" & Chiefdom== "Gorama Kono"
	replace Chiefdom= "Kamara" if District== "Kono" & Chiefdom== "Kamara"
	replace Chiefdom= "Lei" if District== "Kono" & Chiefdom== "Lei"
	replace Chiefdom= "Nimikoro" if District== "Kono" & Chiefdom== "Nimikoro"
	replace Chiefdom= "Nimiyama" if District== "Kono" & Chiefdom== "Nimiyama"
	replace Chiefdom= "Sandor" if District== "Kono" & Chiefdom== "Sandor"
	replace Chiefdom= "Soa" if District== "Kono" & Chiefdom== "Soa"
	replace Chiefdom= "Tankoro" if District== "Kono" & Chiefdom== "Tankoro"
	replace Chiefdom= "Bahruwa" if District== "Moyamba" & Chiefdom== "Bagruwa"
	replace Chiefdom= "Bumpeh" if District== "Moyamba" & Chiefdom== "Bumpeh"		 
	replace Chiefdom= "Fakunya" if District== "Moyamba" & Chiefdom== "Fakunya"
	replace Chiefdom= "Kagboro" if District== "Moyamba" & Chiefdom== "Kargboro"
	replace Chiefdom= "Kaiyamba" if District== "Moyamba" & Chiefdom== "Kaiyamba"
	replace Chiefdom= "Kori" if District== "Moyamba" & Chiefdom== "Kori"
	replace Chiefdom= "Kowa" if District== "Moyamba" & Chiefdom== "Kowa"
	replace Chiefdom= "Lower Banta (Gbanbatoke)" if District== "Moyamba" & Chiefdom== "Banta Gbangbatote"
	replace Chiefdom= "Ribbi" if District== "Moyamba" & Chiefdom== "Ribbi"
	replace Chiefdom= "Timbale" if District== "Moyamba" & Chiefdom== "Timidale"
	replace Chiefdom= "Upper Banta (Mokele)" if District== "Moyamba" & Chiefdom== "Banta Mokele"
	replace Chiefdom= "Bureh Kasseh Makonteh (BKM)" if District== "Port Loko" & Chiefdom== "Bkm"
	replace Chiefdom= "Buya" if District== "Port Loko" & Chiefdom== "Buya Romende"
	replace Chiefdom= "Dibia" if District== "Port Loko" & Chiefdom== "Dibia"
	replace Chiefdom= "Kaffu Bullom" if District== "Port Loko" & Chiefdom== "Kaffu Bullom"
	replace Chiefdom= "Koya" if District== "Port Loko" & Chiefdom== "Koya"
	replace Chiefdom= "Lokomasama" if District== "Port Loko" & Chiefdom== "Lokomasam"
	replace Chiefdom= "Maforki" if District== "Port Loko" & Chiefdom== "Maforki"
	replace Chiefdom= "Marampa" if District== "Port Loko" & Chiefdom== "Marampa"
	replace Chiefdom= "Masimera" if District== "Port Loko" & Chiefdom== "Masimera"
	replace Chiefdom= "Sanda Magbolontor" if District== "Port Loko" & Chiefdom== "Sanda Magbolontor"
	replace Chiefdom= "Tinkatupa Maka Saffroko (TMS)" if District== "Port Loko" & Chiefdom== "Tms"
	replace Chiefdom= "Barri" if District== "Pujehun" & Chiefdom== "Barri"
	replace Chiefdom= "Galliness Perri" if District== "Pujehun" & Chiefdom== "Gallinas-Perri"
	replace Chiefdom= "Kpaka" if District== "Pujehun" & Chiefdom== "Kpaka"
	replace Chiefdom= "Makpele" if District== "Pujehun" & Chiefdom== "Makpele"
	replace Chiefdom= "Malen" if District== "Pujehun" & Chiefdom== "Malen"
	replace Chiefdom= "Mono Sakrim" if District== "Pujehun" & Chiefdom== "Mano-Sakrim"
	replace Chiefdom= "Panga Kabonde" if District== "Pujehun" & Chiefdom== "Kpanga Kabonde"
	replace Chiefdom= "Panga Krim" if District== "Pujehun" & Chiefdom== "Panga Krim"
	replace Chiefdom= "Pejeh (Futa Pejeh)" if District== "Pujehun" & Chiefdom== "Pejeh"
	replace Chiefdom= "Soro Gbema" if District== "Pujehun" & Chiefdom== "Soro-Gbeima"
	replace Chiefdom= "Gbonkolenken" if District== "Tonkolili" & Chiefdom== "Gbonkolenken"
	replace Chiefdom= "Kafe Simiria" if District== "Tonkolili" & Chiefdom== "Kafe Simiria"
	replace Chiefdom= "Kalansogoia" if District== "Tonkolili" & Chiefdom== "Kalansongoia"
	replace Chiefdom= "Kholifa Mabang" if District== "Tonkolili" & Chiefdom== "Kholifa Mabang"
	replace Chiefdom= "Kholifa Rowala" if District== "Tonkolili" & Chiefdom== "Kholifa"
	replace Chiefdom= "Kunike" if District== "Tonkolili" & Chiefdom== "Konike Sanda"
	replace Chiefdom= "Kunike Barina" if District== "Tonkolili" & Chiefdom== "Konike Barina"
	replace Chiefdom= "Malal Mara" if District== "Tonkolili" & Chiefdom== "Malal Mara"
	replace Chiefdom= "Tane" if District== "Tonkolili" & Chiefdom== "Tane"
	replace Chiefdom= "Yoni" if District== "Tonkolili" & Chiefdom== "Yoni"
	********************************************
	replace District=trim(upper(District))
	replace Chiefdom=trim(upper(Chiefdom))
	sort District Chiefdom
	save 02_temp/pnas.1518587113.sd02_suspected.dta,replace

********
** NPS data
********
	
** NPS-2007cm
	use "01_data/nps-2007_cm_clean.dta", clear
	tab k29 
	tab k31 
	tab k39 
	tab k40
	collapse k29 k39 k31 k40, by(chief_2004census)
	ren chief_2004census CHIEFDOM
	sort CHIEFDOM
	save 02_temp/NPS2007cm.dta,replace

** NPS-2007hh
	use "01_data/nps-2007_hh_clean.dta", clear
	tab h1a
	tab h1b
	tab h1c
	collapse h1a h1b h1c, by(chief_2004census)
	ren chief_2004census CHIEFDOM
	sort CHIEFDOM
	save 02_temp/NPS2007hh.dta,replace

********
** Neighbors
********

	use 01_data/chiefdom_neighbors_matrix.dta, clear
	save 02_temp/chiefdom_neighbors_matrix.dta,replace

********
** Shapefile data to create figure
********
	
	clear
	shp2dta using "01_data/Sierra Leone District Boundaries/SL_admin_chiefdom.shp", data("02_temp/d_data") coor("02_temp/d_coord") genid(id) replace
	* make it so that it can be connected with the main dataset
	use "02_temp/d_data", clear
	ren NAME_3 Chiefdom
	ren NAME_2 District
	replace Chiefdom=trim(upper(Chiefdom))
	replace District=trim(upper(District))
	sort District Chiefdom

	replace Chiefdom= "BADJIA" if District== "BO" & Chiefdom== "BADJIA"
	replace Chiefdom= "BAGBO" if District== "BO" & Chiefdom== "BAGBO"
	replace Chiefdom= "BAGBWE" if District== "BO" & Chiefdom== "BAGBE"
	replace Chiefdom= "BAOMA" if District== "BO" & Chiefdom== "BOAMA"
	replace Chiefdom= "BUMPE NGAO" if District== "BO" & Chiefdom== "BUMPEH"
	replace Chiefdom= "GBO" if District== "BO" & Chiefdom== "GBO"
	replace Chiefdom= "JAIAMA BONGOR" if District== "BO" & Chiefdom== "JIAMA-BONGOR"
	replace Chiefdom= "KAKUA" if District== "BO" & Chiefdom== "KAKUA"
	replace Chiefdom= "KOMBOYA" if District== "BO" & Chiefdom== "KOMBOYA"
	replace Chiefdom= "LUGBU" if District== "BO" & Chiefdom== "LUGBU"
	replace Chiefdom= "NIAWA LENGA" if District== "BO" & Chiefdom== "NIAWA LENGA"
	replace Chiefdom= "SELENGA" if District== "BO" & Chiefdom== "SELENGA"
	replace Chiefdom= "TIKONKO" if District== "BO" & Chiefdom== "TIKONKO"
	replace Chiefdom= "VALUNIA" if District== "BO" & Chiefdom== "VALUNIA"
	replace Chiefdom= "WONDE" if District== "BO" & Chiefdom== "WUNDE"
	replace Chiefdom= "BIRIWA" if District== "BOMBALI" & Chiefdom== "BIRIWA"
	replace Chiefdom= "BOMBALI SEBORA" if District== "BOMBALI" & Chiefdom== "BOMBALI SEBORA"
	replace Chiefdom= "GBANTI KAMARANKA" if District== "BOMBALI" & Chiefdom== "GBANTI KAMARANKA"
	replace Chiefdom= "GBENDEMBU NGOWAHUN" if District== "BOMBALI" & Chiefdom== "GBENDEMBU NGOWAHUN"
	replace Chiefdom= "LIBEISAYGAHUN" if District== "BOMBALI" & Chiefdom== "LIBEISAYGAHUN"
	replace Chiefdom= "MAGBAIMBA NDORHAHUN" if District== "BOMBALI" & Chiefdom== "MAGBEMBA GOWAHUN"
	replace Chiefdom= "MAKARI GBANTI" if District== "BOMBALI" & Chiefdom== "MAKARI GBANTI"
	replace Chiefdom= "PAKI MASABONG" if District== "BOMBALI" & Chiefdom== "PAKI MASABONG"
	replace Chiefdom= "SAFROKO LIMBA" if District== "BOMBALI" & Chiefdom== "SAFROKO LIMBA"
	replace Chiefdom= "SANDA LOKO" if District== "BOMBALI" & Chiefdom== "SANDA LOKO"
	replace Chiefdom= "SANDA TENDARAN" if District== "BOMBALI" & Chiefdom== "SANDA TENDAREN"
	replace Chiefdom= "SELLA LIMBA" if District== "BOMBALI" & Chiefdom== "SELLA LIMBA"
	replace Chiefdom= "TAMBAKHA" if District== "BOMBALI" & Chiefdom== "TAMBAKHA"
	replace Chiefdom= "BENDU-CHA" if District== "BONTHE" & Chiefdom== "BENDU CHA"
	replace Chiefdom= "BUM" if District== "BONTHE" & Chiefdom== "BUM"
	replace Chiefdom= "DEMA" if District== "BONTHE" & Chiefdom== "DEMA"
	replace Chiefdom= "IMPERRI" if District== "BONTHE" & Chiefdom== "IMPERI"
	replace Chiefdom= "JONG" if District== "BONTHE" & Chiefdom== "JONG"
	replace Chiefdom= "KPANDA KEMO" if District== "BONTHE" & Chiefdom== "KPANDA KEMO"
	replace Chiefdom= "KWAMEBAI KRIM" if District== "BONTHE" & Chiefdom== "KWAMEBAI KRIM"
	replace Chiefdom= "NONGOBA" if District== "BONTHE" & Chiefdom== "NONGOBA BULLOM"
	replace Chiefdom= "SOGBENI" if District== "BONTHE" & Chiefdom== "SOGBINI"
	replace Chiefdom= "YAWBEKO" if District== "BONTHE" & Chiefdom== "YAWBEKO"
	replace Chiefdom= "DEA" if District== "KAILAHUN" & Chiefdom== "DIA"
	replace Chiefdom= "JAWIE" if District== "KAILAHUN" & Chiefdom== "JAWIE"
	replace Chiefdom= "KISSI KAMA" if District== "KAILAHUN" & Chiefdom== "KISSI KAMA"
	replace Chiefdom= "KISSI TENG" if District== "KAILAHUN" & Chiefdom== "KISSI TENG"
	replace Chiefdom= "KISSI TONGI" if District== "KAILAHUN" & Chiefdom== "KISSI TONGI"
	replace Chiefdom= "KPEJE BONGRE" if District== "KAILAHUN" & Chiefdom== "PEHE BONGRE"
	replace Chiefdom= "KPEJE WEST" if District== "KAILAHUN" & Chiefdom== "PEJE WEST"
	replace Chiefdom= "LUAWA" if District== "KAILAHUN" & Chiefdom== "LUAWA"
	replace Chiefdom= "MALEMA" if District== "KAILAHUN" & Chiefdom== "MALEMA"
	replace Chiefdom= "MANDU" if District== "KAILAHUN" & Chiefdom== "MANDU"
	replace Chiefdom= "NJALUAHUN" if District== "KAILAHUN" & Chiefdom== "NJALUAHUN"
	replace Chiefdom= "PENGUIA" if District== "KAILAHUN" & Chiefdom== "PENGUIA"
	replace Chiefdom= "UPPER BAMBARA" if District== "KAILAHUN" & Chiefdom== "UPPER BAMBARA"
	replace Chiefdom= "YAWEI" if District== "KAILAHUN" & Chiefdom== "YAWEI"
	replace Chiefdom= "BRAMAIA" if District== "KAMBIA" & Chiefdom== "BRAMAIA"
	replace Chiefdom= "GBINLE DIXIN" if District== "KAMBIA" & Chiefdom== "GBINLEH-DIXON"
	replace Chiefdom= "MABOLO" if District== "KAMBIA" & Chiefdom== "MAMBOLO"
	replace Chiefdom= "MAGBEMA" if District== "KAMBIA" & Chiefdom== "MAGBEMA"
	replace Chiefdom= "MASUNGBALA" if District== "KAMBIA" & Chiefdom== "MASUNGBALA"
	replace Chiefdom= "SAMU" if District== "KAMBIA" & Chiefdom== "SAMU"
	replace Chiefdom= "TONKO LIMBA" if District== "KAMBIA" & Chiefdom== "TONKO LIMBA"
	replace Chiefdom= "DAMA" if District== "KENEMA" & Chiefdom== "DAMA"
	replace Chiefdom= "DODO" if District== "KENEMA" & Chiefdom== "DODO"
	replace Chiefdom= "GAURA" if District== "KENEMA" & Chiefdom== "GAURA"
	replace Chiefdom= "GORAMA MENDE" if District== "KENEMA" & Chiefdom== "GORAMA MENDE"
	replace Chiefdom= "KANDU LEPPIAMA" if District== "KENEMA" & Chiefdom== "KANDO LEPPEAMA"
	replace Chiefdom= "KOYA" if District== "KENEMA" & Chiefdom== "KOYA"
	replace Chiefdom= "LANGRAMA" if District== "KENEMA" & Chiefdom== "LANGRAMA"
	replace Chiefdom= "LOWER BAMBARA" if District== "KENEMA" & Chiefdom== "LOWER BAMBARA"
	replace Chiefdom= "MALEGOHUN" if District== "KENEMA" & Chiefdom== "MALEGOHUN"
	replace Chiefdom= "NIAWA" if District== "KENEMA" & Chiefdom== "NIAWA"
	replace Chiefdom= "NOMO" if District== "KENEMA" & Chiefdom== "NOMO"
	replace Chiefdom= "NONGOWA" if District== "KENEMA" & Chiefdom== "NONGOWA"
	replace Chiefdom= "SIMBARU" if District== "KENEMA" & Chiefdom== "SIMBARU"
	replace Chiefdom= "SMALL BO" if District== "KENEMA" & Chiefdom== "SMALL BO"
	replace Chiefdom= "TUNKIA" if District== "KENEMA" & Chiefdom== "TUNKIA"
	replace Chiefdom= "WANDOR" if District== "KENEMA" & Chiefdom== "WANDOR"
	replace Chiefdom= "DIANG" if District== "KOINADUGU" & Chiefdom== "DIANG"
	replace Chiefdom= "FOLOSABA DEMBELIA" if District== "KOINADUGU" & Chiefdom== "FOLLOSABA DEMBELIA"
	replace Chiefdom= "KASUNKO" if District== "KOINADUGU" & Chiefdom== "KASSUNKO"
	replace Chiefdom= "MONGO" if District== "KOINADUGU" & Chiefdom== "MONGO"
	replace Chiefdom= "NIENI" if District== "KOINADUGU" & Chiefdom== "NEINI"
	replace Chiefdom= "NEYA" if District== "KOINADUGU" & Chiefdom== "NEYA"
	replace Chiefdom= "SENGBE" if District== "KOINADUGU" & Chiefdom== "SENGBE"
	replace Chiefdom= "SINKUNIA" if District== "KOINADUGU" & Chiefdom== "DEMBELIA SINKUNIA"
	replace Chiefdom= "SULIMA" if District== "KOINADUGU" & Chiefdom== "SULIMA"
	replace Chiefdom= "WARA WARA BAFODIA" if District== "KOINADUGU" & Chiefdom== "WARA WARA BAFODIA"
	replace Chiefdom= "WARA WARA YAGALA" if District== "KOINADUGU" & Chiefdom== "WARA WARA YAGALA"
	replace Chiefdom= "FIAMA" if District== "KONO" & Chiefdom== "FIAMA"
	replace Chiefdom= "GBANE" if District== "KONO" & Chiefdom== "GBANE"
	replace Chiefdom= "GBANE KANDOR" if District== "KONO" & Chiefdom== "GBANE KANDOR"
	replace Chiefdom= "GBENSE" if District== "KONO" & Chiefdom== "GBENSE"
	replace Chiefdom= "GORAMA KONO" if District== "KONO" & Chiefdom== "GORAMA KONO"
	replace Chiefdom= "KAMARA" if District== "KONO" & Chiefdom== "KAMARA"
	replace Chiefdom= "LEI" if District== "KONO" & Chiefdom== "LEI"
	replace Chiefdom= "MAFINDOR" if District== "KONO" & Chiefdom== "MAFINDOR"
	replace Chiefdom= "NIMIKORO" if District== "KONO" & Chiefdom== "NIMIKORO"
	replace Chiefdom= "NIMIYAMA" if District== "KONO" & Chiefdom== "NIMIYAMA"
	replace Chiefdom= "SANDOR" if District== "KONO" & Chiefdom== "SANDOR"
	replace Chiefdom= "SOA" if District== "KONO" & Chiefdom== "SOA"
	replace Chiefdom= "TANKORO" if District== "KONO" & Chiefdom== "TANKORO"
	replace Chiefdom= "TOLI" if District== "KONO" & Chiefdom== "TOLI"
	replace Chiefdom= "BAHRUWA" if District== "MOYAMBA" & Chiefdom== "BAGRUWA"
	replace Chiefdom= "BUMPEH" if District== "MOYAMBA" & Chiefdom== "BUMPE"
	replace Chiefdom= "DASSE" if District== "MOYAMBA" & Chiefdom== "DASSE"
	replace Chiefdom= "FAKUNYA" if District== "MOYAMBA" & Chiefdom== "FAKUNYA"
	replace Chiefdom= "KAGBORO" if District== "MOYAMBA" & Chiefdom== "KAGBORO"
	replace Chiefdom= "KAIYAMBA" if District== "MOYAMBA" & Chiefdom== "KAIYAMBA"
	replace Chiefdom= "KAMAJEI" if District== "MOYAMBA" & Chiefdom== "KAMAJEL"
	replace Chiefdom= "KONGBORA" if District== "MOYAMBA" & Chiefdom== "KANGBORA"
	replace Chiefdom= "KORI" if District== "MOYAMBA" & Chiefdom== "KORI"
	replace Chiefdom= "KOWA" if District== "MOYAMBA" & Chiefdom== "KOWA"
	replace Chiefdom= "LOWER BANTA (GBANBATOKE)" if District== "MOYAMBA" & Chiefdom== "BANTA GBANGBATOTE"
	replace Chiefdom= "RIBBI" if District== "MOYAMBA" & Chiefdom== "RIBBI"
	replace Chiefdom= "TIMBALE" if District== "MOYAMBA" & Chiefdom== "TIMDEL"
	replace Chiefdom= "UPPER BANTA (MOKELE)" if District== "MOYAMBA" & Chiefdom== "BANTA MOKELE"
	replace Chiefdom= "BUREH KASSEH MAKONTEH (BKM)" if District== "PORT LOKO" & Chiefdom== "BUREH"
	replace Chiefdom= "BUYA" if District== "PORT LOKO" & Chiefdom== "BUYA ROMENDE"
	replace Chiefdom= "DIBIA" if District== "PORT LOKO" & Chiefdom== "DIBIA"
	replace Chiefdom= "KAFFU BULLOM" if District== "PORT LOKO" & Chiefdom== "KAFFU BULLOM"
	replace Chiefdom= "KOYA" if District== "PORT LOKO" & Chiefdom== "KOYA"
	replace Chiefdom= "LOKOMASAMA" if District== "PORT LOKO" & Chiefdom== "LOKO MASSAMA"
	replace Chiefdom= "MAFORKI" if District== "PORT LOKO" & Chiefdom== "MAFORKI"
	replace Chiefdom= "MARAMPA" if District== "PORT LOKO" & Chiefdom== "MARAMPA"
	replace Chiefdom= "MASIMERA" if District== "PORT LOKO" & Chiefdom== "MASIMERA"
	replace Chiefdom= "SANDA MAGBOLONTOR" if District== "PORT LOKO" & Chiefdom== "SANDA MAGBOLONTOR"
	replace Chiefdom= "TINKATUPA MAKA SAFFROKO (TMS)" if District== "PORT LOKO" & Chiefdom== "TINKATUPA MAKAMA SAFROKO"
	replace Chiefdom= "BARRI" if District== "PUJEHUN" & Chiefdom== "BARRI"
	replace Chiefdom= "GALLINESS PERRI" if District== "PUJEHUN" & Chiefdom== "GALLINAS PERI"
	replace Chiefdom= "KPAKA" if District== "PUJEHUN" & Chiefdom== "KPAKA"
	replace Chiefdom= "MAKPELE" if District== "PUJEHUN" & Chiefdom== "MAKPELE"
	replace Chiefdom= "MALEN" if District== "PUJEHUN" & Chiefdom== "MALEN"
	replace Chiefdom= "MONO SAKRIM" if District== "PUJEHUN" & Chiefdom== "MANO SAKRIM"
	replace Chiefdom= "PANGA KABONDE" if District== "PUJEHUN" & Chiefdom== "PANGA KABONDE"
	replace Chiefdom= "PANGA KRIM" if District== "PUJEHUN" & Chiefdom== "PANGA KRIM"
	replace Chiefdom= "PEJEH (FUTA PEJEH)" if District== "PUJEHUN" & Chiefdom== "PEJEH"
	replace Chiefdom= "SORO GBEMA" if District== "PUJEHUN" & Chiefdom== "SORO GBEMA"
	replace Chiefdom= "SOWA" if District== "PUJEHUN" & Chiefdom== "SOWA"
	replace Chiefdom= "YAKEMU KPUKUMU KRIM" if District== "PUJEHUN" & Chiefdom== "YAKEMO-KPUKUMU KRIM"
	replace Chiefdom= "GBONKOLENKEN" if District== "TONKOLILI" & Chiefdom== "GBONKOLENKEN"
	replace Chiefdom= "KAFE SIMIRIA" if District== "TONKOLILI" & Chiefdom== "KAFE SIMIRA"
	replace Chiefdom= "KALANSOGOIA" if District== "TONKOLILI" & Chiefdom== "KALANSOGOIA"
	replace Chiefdom= "KHOLIFA MABANG" if District== "TONKOLILI" & Chiefdom== "KHOLIFA MABANG"
	replace Chiefdom= "KHOLIFA ROWALA" if District== "TONKOLILI" & Chiefdom== "KHOLIFA ROWALLA"
	replace Chiefdom= "KUNIKE" if District== "TONKOLILI" & Chiefdom== "KONIKE BARINA"
	replace Chiefdom= "KUNIKE BARINA" if District== "TONKOLILI" & Chiefdom== "KONIKE SANDA"
	replace Chiefdom= "MALAL MARA" if District== "TONKOLILI" & Chiefdom== "MALAL MARA"
	replace Chiefdom= "SAMBAYA" if District== "TONKOLILI" & Chiefdom== "SAMBAIA BENDUGU"
	replace Chiefdom= "TANE" if District== "TONKOLILI" & Chiefdom== "TANE"
	replace Chiefdom= "YONI" if District== "TONKOLILI" & Chiefdom== "YONI"	
	save 02_temp/d_data.dta,replace
	
********
** Ruggedness
********

* data from ARC GIS
	
	import excel "01_data/ruggedness_by_chiefdom_SL_30m_1km.xlsx", sheet("Sheet1") firstrow clear

	ren _ruggmean30m ruggmean30m
	ren _ruggstdev30m ruggstdev30m 
	ren _ruggmin30m ruggmin30m
	ren _ruggmax30m ruggmax30m
	ren _Elevmean30m Elevmean30m 
	ren _Elevstdev30m Elevstdev30m 
	ren _Elevmin30m Elevmin30m
	ren _Elevmax30m Elevmax30m 
	ren _slopemean30m slopemean30m 
	ren _slopestdev30m slopestdev30m 
	ren _slopemin30m slopemin30m 
	ren _slopemax30m slopemax30m 
	ren _elevmean1km elevmean1km 
	ren _elevtsd1km elevtsd1km 
	ren _elevmin1km elevmin1km 
	ren _elevmax1km elevmax1km 
	ren _slopemean1km slopemean1km 
	ren _slopestdev1km slopestdev1km 
	ren _slopemin1km slopemin1km 
	ren _slopemax1km slopemax1km 
	ren _ruggmean1km ruggmean1km 
	ren _ruggstdev1km ruggstdev1km
	ren _ruggmin1km ruggmin1km 
	ren _ruggmax1km ruggmax1km
	
	
	drop PROVINCE
	ren DISTRICT DISTRICT_rug
	* correct names
	replace Chiefdom= "BAGBWE" if DISTRICT_rug== "Bo" & Chiefdom== "BAGBE"
	replace Chiefdom= "BUMPE NGAO" if DISTRICT_rug== "Bo" & Chiefdom== "BUMPEH"
	replace Chiefdom= "JAIAMA BONGOR" if DISTRICT_rug== "Bo" & Chiefdom== "JIAMA-BONGOR"
	replace Chiefdom= "SELENGA" if DISTRICT_rug== "Bo" & Chiefdom== "SIELENGA"
	replace Chiefdom= "WONDE" if DISTRICT_rug== "Bo" & Chiefdom== "WUNDE"

	replace Chiefdom= "BOMBALI SEBORA" if DISTRICT_rug== "Bombali" & Chiefdom== "BOMBALI SHEBORA"
	replace Chiefdom= "LIBEISAYGAHUN" if DISTRICT_rug== "Bombali" & Chiefdom== "LEIBASGAYAHUN"
	replace Chiefdom= "MAGBAIMBA NDORHAHUN" if DISTRICT_rug== "Bombali" & Chiefdom== "MAGBAIAMBA NGOWAHUA"
	replace Chiefdom= "SANDA TENDARAN" if DISTRICT_rug== "Bombali" & Chiefdom== "SANDA TENDAREN"
	replace Chiefdom= "TAMBAKHA" if DISTRICT_rug== "Bombali" & Chiefdom== "TAMBAKKA"

	replace Chiefdom= "BENDU-CHA" if DISTRICT_rug== "Bonthe" & Chiefdom== "BENDUCHA"
	replace Chiefdom= "IMPERRI" if DISTRICT_rug== "Bonthe" & Chiefdom== "IMPERI"
	replace Chiefdom= "KWAMEBAI KRIM" if DISTRICT_rug== "Bonthe" & Chiefdom== "KWAMABAI KRIM"
	replace Chiefdom= "NONGOBA" if DISTRICT_rug== "Bonthe" & Chiefdom== "NONGOBA BULLOM"
	replace Chiefdom= "SOGBENI" if DISTRICT_rug== "Bonthe" & Chiefdom== "SOGBINI"
	
	replace Chiefdom= "DEA" if DISTRICT_rug== "Kailahun" & Chiefdom== "DIA"
	replace Chiefdom= "NJALUAHUN" if DISTRICT_rug== "Kailahun" & Chiefdom== "NJALUWAHUN"
	replace Chiefdom= "KPEJE BONGRE" if DISTRICT_rug== "Kailahun" & Chiefdom== "PEJE BONGRE"
	replace Chiefdom= "KPEJE WEST" if DISTRICT_rug== "Kailahun" & Chiefdom== "PEJE WEST"

	replace Chiefdom= "GBINLE DIXIN" if DISTRICT_rug== "Kambia" & Chiefdom== "GBINLEH-DIXON"
	replace Chiefdom= "MABOLO" if DISTRICT_rug== "Kambia" & Chiefdom== "MAMBOLO"
	
	replace Chiefdom= "KANDU LEPPIAMA" if DISTRICT_rug== "Kenema" & Chiefdom== "KANDO LEPPEAMA"
	replace Chiefdom= "LANGRAMA" if DISTRICT_rug== "Kenema" & Chiefdom== "LANGORAMA"

	replace Chiefdom= "FOLOSABA DEMBELIA" if DISTRICT_rug== "Koinadugu" & Chiefdom== "DEMBELIA MUSAIA"
	replace Chiefdom= "SINKUNIA" if DISTRICT_rug== "Koinadugu" & Chiefdom== "DEMBELIA SINKUNIA"
	replace Chiefdom= "KASUNKO" if DISTRICT_rug== "Koinadugu" & Chiefdom== "KASSUNKO"
	
	replace Chiefdom= "BAHRUWA" if DISTRICT_rug== "Moyamba" & Chiefdom== "BAGRUWA"
	replace Chiefdom= "LOWER BANTA (GBANBATOKE)" if DISTRICT_rug== "Moyamba" & Chiefdom== "BANTA GBANGBATOKE"
	replace Chiefdom= "TIMBALE" if DISTRICT_rug== "Moyamba" & Chiefdom== "TIMDEL"
	replace Chiefdom= "UPPER BANTA (MOKELE)" if DISTRICT_rug== "Moyamba" & Chiefdom== "BANTA MOKELE"
	
	replace Chiefdom= "BUREH KASSEH MAKONTEH (BKM)" if DISTRICT_rug== "Port Loko" & Chiefdom== "BUREH"
	replace Chiefdom= "TINKATUPA MAKA SAFFROKO (TMS)" if DISTRICT_rug== "Port Loko" & Chiefdom== "TINKATUPA MAKA SAFFOKO"
	replace Chiefdom= "LOKOMASAMA" if DISTRICT_rug== "Port Loko" & Chiefdom== "LOKO MASAMA"
	replace Chiefdom= "BUYA" if DISTRICT_rug== "Port Loko" & Chiefdom== "BUYA ROMENDE"
	replace Chiefdom= "SANDA MAGBOLONTOR" if DISTRICT_rug== "Port Loko" & Chiefdom== "SANDA MAGBLONTHOR"
		
	replace Chiefdom= "GALLINESS PERRI" if DISTRICT_rug== "Pujehun" & Chiefdom== "GALLINASPERI"
	replace Chiefdom= "MONO SAKRIM" if DISTRICT_rug== "Pujehun" & Chiefdom== "MANO SAKRIM BENDUGU"
	replace Chiefdom= "PANGA KABONDE" if DISTRICT_rug== "Pujehun" & Chiefdom== "PANGA-KABONDE"
	replace Chiefdom= "PEJEH (FUTA PEJEH)" if DISTRICT_rug== "Pujehun" & Chiefdom== "PEJEH"
	replace Chiefdom= "YAKEMU KPUKUMU KRIM" if DISTRICT_rug== "Pujehun" & Chiefdom== "YAKEMO-KPUKUMU KRIM"
	replace Chiefdom= "MONO SAKRIM" if DISTRICT_rug== "Pujehun" & Chiefdom== "MANO SAKRIM"

	replace Chiefdom= "KAFE SIMIRIA" if DISTRICT_rug== "Tonkolili" & Chiefdom== "KAFE SIMIRA"
	replace Chiefdom= "KHOLIFA ROWALA" if DISTRICT_rug== "Tonkolili" & Chiefdom== "KHOLIFA ROWALLA SIMIRA"
	replace Chiefdom= "SAMBAYA" if DISTRICT_rug== "Tonkolili" & Chiefdom== "SAMBAIA BENDUGU"
	replace Chiefdom= "KUNIKE BARINA" if DISTRICT_rug== "Tonkolili" & Chiefdom== "KONIKE SANDE"
	replace Chiefdom= "KHOLIFA ROWALA" if DISTRICT_rug== "Tonkolili" & Chiefdom== "KHOLIFA ROWALLA"
	replace Chiefdom= "KUNIKE" if DISTRICT_rug== "Tonkolili" & Chiefdom== "KONIKE BARINA"
	
	drop if DISTRICT_rug== "Western Area" 
	
	drop DISTRICT_rug
	
	save 02_temp/rugedness.dta,replace

********
** Combine datasets
********

	* Merge all to Core.dta
	* We always have n==149
	use 01_data/Core.dta, clear

	* merge Acemoglu et al (2014) in
	merge 1:1 CHIEFDOM using 02_temp/chiefs_survey_clean_out.dta
	drop _m

	* merge confirmed cases in
	merge 1:1 District Chiefdom using 02_temp/pnas.1518587113.sd02_confirmed.dta
	* 2 cases cant be accommodated
	drop if _m==2
	drop _m
	* Places with no ebola data is "zero cases"
	replace ebola_confirmed=0 if ebola_confirmed==.
	replace ebola_confirmedSUB1=0 if ebola_confirmedSUB1==.
	replace ebola_confirmedSUB2=0 if ebola_confirmedSUB2==.
	replace ebola_confirmedSUB3=0 if ebola_confirmedSUB3==.
	replace ebola_confirmedSUB4=0 if ebola_confirmedSUB4==.
	replace ebola_confirmedSUB5=0 if ebola_confirmedSUB5==.
	replace ebola_confirmedSUB6=0 if ebola_confirmedSUB6==.
	replace ebola_confirmedSUB7=0 if ebola_confirmedSUB7==.
	replace ebola_confirmedSUB8=0 if ebola_confirmedSUB8==.
	replace ebola_confirmedSUB9=0 if ebola_confirmedSUB9==.
	replace ebola_confirmedSUB10=0 if ebola_confirmedSUB10==.
	replace ebola_confirmedSUB11=0 if ebola_confirmedSUB11==.
	replace ebola_confirmedSUB12=0 if ebola_confirmedSUB12==.

	* merge suspected cases in
	merge 1:1 District Chiefdom using 02_temp/pnas.1518587113.sd02_suspected.dta
	* 2 cases cant be accommodated
	drop if _m==2
	drop _m
	* Places with no ebola data is "zero cases"
	replace ebola_suspected=0 if ebola_suspected==.
	
	* merge NPS in	
	merge 1:1 CHIEFDOM using 02_temp/NPS2007cm.dta
	* Gbo(3106) and Yawbeko (3211) are missing from the NPS
	drop if _m==2
	drop _m
	merge 1:1 CHIEFDOM using 02_temp/NPS2007hh.dta
	* Gbo(3106) and Yawbeko (3211) are missing from the NPS
	drop if _m==2
	drop _m

	* merge neighborhood info in
	merge 1:1 District Chiefdom using 02_temp/chiefdom_neighbors_matrix.dta
	drop _m	

	* merge gps info (for figures) in
	merge 1:1 District Chiefdom using 02_temp/d_data.dta
	* C=Sittia in B=Bonthe is missing in GPS data, and GPS data has freetown 5x	
	drop if _m==2
	drop _m	

	* merge rugedness
	merge 1:1 District Chiefdom using 02_temp/rugedness.dta
	drop _m	
	
********
** Save dataset
********

	save 03_output/Dataset.dta,replace
	
** END **
